// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Eggman Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias 73 : TYPE_EGGMAN


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		temp0 = object.xpos
		temp0 -= 0x880000
		if object[0].xpos >= temp0
			object.state++
			object.value0 = 180
			object.animation = 1
		end if
		break
	case 1
		object.value0--
		if object.value0 < 0
			object.state++
			object.value0 = 15
			object.animation = 2
		end if
		break
	case 2
		object.value0--
		if object.value0 < 0
			object.state++
			object.xvel = -0xFC00
			object.yvel = -0x3C000
		end if
		break
	case 3
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x2400
		if object.yvel == 0
			object.animation = 1
			object.state++
		end if
		break
	case 4
		object.animation = 1
		object.state++
		break
	end switch
	switch object.animation
	case 0
		object.frame = 0
		break
	case 1
		object.animationTimer++
		if object.animationTimer == 14
			object.animationTimer = 0
		end if
		object.frame = object.animationTimer
		object.frame /= 7
		object.frame++
		break
	case 2
		if object.yvel == 0
			object.frame = 3
		else
			object.frame = 4
		end if
		break
	case 3
		if object.yvel == 0
			object.frame = 5
		else
			object.frame = 6
		end if
		break
	end switch
	if object.value1 != 0
		object.value1--
	end if
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -14, -20, 14, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			if object.value1 == 0
				CallFunction(PlayerObject_CheckHit)
				if checkResult == 1
					object.animation = 3
					object.value1 = 32
				else
					if object.yvel == 0
						object.animation = 1
					end if
				end if
			end if
		end if
	next
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-22, -23, 32, 54, 50, 295)
	SpriteFrame(-22, -24, 32, 54, 84, 261)
	SpriteFrame(-22, -23, 32, 54, 84, 316)
	SpriteFrame(-16, -16, 46, 44, 350, 165)
	SpriteFrame(-16, -23, 46, 55, 350, 210)
	SpriteFrame(-22, -24, 32, 54, 192, 266)
	SpriteFrame(-30, -24, 60, 44, 289, 165)
	SpriteFrame(-24, -23, 58, 44, 234, 221)
	SpriteFrame(-21, -25, 51, 52, 269, 213)
	SpriteFrame(-22, -20, 42, 64, 225, 319)
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
